package com.onlinelearn.courseservice.controller;

import com.onlinelearn.courseservice.dto.HomeworkSubmissionDTO;
import com.onlinelearn.courseservice.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/homeworks")
public class HomeworkController {
    @Autowired
    private HomeworkService homeworkService;

    @PostMapping("/submit")
    public ResponseEntity<HomeworkSubmissionDTO> submitHomework(
            @RequestBody HomeworkSubmissionDTO submissionDTO
    ) {
        HomeworkSubmissionDTO submission = homeworkService.submitHomework(submissionDTO);
        return ResponseEntity.ok(submission);
    }

    @PostMapping("/{homeworkId}/grade")
    public ResponseEntity<Void> gradeHomework(
            @PathVariable Long homeworkId,
            @RequestParam Long studentId,
            @RequestParam Integer grade
    ) {
        homeworkService.gradeHomework(homeworkId, studentId, grade);
        return ResponseEntity.ok().build();
    }
} 